using System;
using System.Collections.Generic;
using System.Text;
using EFFC.Net.Common;
using EFFC.Net.Interface;

namespace EFFC.Net.Data.Base
{
    public enum ErrorCode
    {
        Normal = 0,
        Warning = 1,
        Err_Logic = 10,
        Err_System = 99
    }
    public class CheckReportStd : StandardData<StringBuilder>
    {

        ErrorCode errorcode;

        public void Write(ErrorCode code, string specify)
        {
            if (this.ErrorCode < code)
            {
                this.errorcode = code;
            }
            this.Value.Append(specify);
        }
        public void Write(ErrorCode code, string specify, string p)
        {
            if (this.ErrorCode < code)
            {
                this.errorcode = code;
            }
            string s = string.Format(specify, p);
            this.Value.Append(s);
        }

        public void Write(ErrorCode code, string specify, string p1, string p2)
        {
            if (this.ErrorCode < code)
            {
                this.errorcode = code;
            }
            string s = string.Format(specify, p1, p2);
            this.Value.Append(s);
        }


        public void Write(ErrorCode code, string specify, params string[] p)
        {
            if (this.ErrorCode < code)
            {
                this.errorcode = code;
            }
            string s = string.Format(specify, p);
            this.Value.Append(s);
        }

        public void WriteLine(ErrorCode code, string specify)
        {
            if (this.ErrorCode < code)
            {
                this.errorcode = code;
            }
            this.Value.AppendLine(specify);
        }

        public void WriteLine(ErrorCode code, string specify, string p)
        {
            if (this.ErrorCode < code)
            {
                this.errorcode = code;
            }
            string s = string.Format(specify, p);
            this.Value.AppendLine(s);
        }

        public void WriteLine(ErrorCode code, string specify, string p1, string p2)
        {
            if (this.ErrorCode < code)
            {
                this.errorcode = code;
            }
            string s = string.Format(specify, p1,p2);
            this.Value.AppendLine(s);
        }


        public void WriteLine(ErrorCode code, string specify, params string[] p)
        {
            if (this.ErrorCode < code)
            {
                this.errorcode = code;
            }
            string s = string.Format(specify, p);
            this.Value.AppendLine(s);
        }

        public void Write(CheckReportStd cr)
        {
            if (cr.ErrorCode > this.ErrorCode)
            {
                this.errorcode = cr.ErrorCode;
            }
            this.Value.Append(cr.Value.ToString());
        }

        public void WriteLine(CheckReportStd cr)
        {
            if (cr.ErrorCode > this.ErrorCode)
            {
                this.errorcode = cr.ErrorCode;
            }
            this.Value.Append(cr.Value.ToString());
        }

        public ErrorCode ErrorCode
        {
            get
            {
                return this.errorcode;
            }
        }


        public override StdType StdType
        {
            get { return StdType.CheckReport; }
        }

        public override string ToStdFormatString()
        {
            string s = "";
            if (errorcode == ErrorCode.Normal)
            {
                s = ExceptionMessage.CheckReportStd.Pass;
            }
            else if (errorcode == ErrorCode.Err_System)
            {
                s = ExceptionMessage.CheckReportStd.System_Error;
            }
            else if (errorcode == ErrorCode.Err_Logic)
            {
                s = ExceptionMessage.CheckReportStd.Logic_Error;
            }
            else if (errorcode == ErrorCode.Warning)
            {
                s = ExceptionMessage.CheckReportStd.Warning;
            }

            if (this.Value.Length > 0)
            {
                return s + BaseMessage.Marks.Colon + "\r\n" + this.Value;
            }
            else
            {
                return s;
            }
        }

        public override string ToString(string format)
        {
            return ToStdFormatString();
        }

        public override string ToString(IFormatProvider format)
        {
            return ToStdFormatString();
        }
    }
}
